import Vue from 'vue'
import VueRouter from 'vue-router'

// 导入登入组件
import Login from '../view/login/login.vue'
// 导入父组件
import layOut from '@/view/layout/index.vue'
// 导入首页子组件
import home from '@/view/home/index.vue'
// 导入问答子组件
import qa from '@/view/QuestionAnswer/index.vue'
// 导入视频子组件
import video from '@/view/video/index.vue'
// 导入我的子组件
import me from '@/view/me/index.vue'
// 导入搜索组件
import search from '@/view/search/index.vue'
// 导入文章详情页
import article from '@/view/articles/index.vue'
// 导入编辑个人信息页面
import setUser from '@/view/edituserinfo/index.vue'
// 导入作者详细页
import autInfo from '@/view/autInfo/index.vue'

Vue.use(VueRouter)

const routes = [
  { path: '/login', component: Login },
  {
    path: '/',
    component: layOut,
    redirect: '/home',
    children: [
      { path: '/home', component: home },
      { path: '/qa', component: qa },
      { path: '/video', component: video },
      { path: '/me', component: me }
    ]
  },
  { path: '/search', component: search },
  // 动态路由
  // props: true 开启props传参
  { name: 'article', path: '/article/:id', component: article, props: true },
  { name: 'setUser', path: '/user/profile', component: setUser },
  {
    name: 'autInfo',
    path: '/autInfo/:id',
    component: autInfo,
    props: true
  }
]

const router = new VueRouter({
  routes
})

export default router
